import sys

class Solution(object):
    def maxProduct(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """

        if len(nums) == 1:
            return nums[0]

        maxValue = -sys.maxsize
        maxPositive = 0
        minNagetive = 0
        for num in nums:
            if num > 0:
                maxPositive, minNagetive = maxPositive*num if maxPositive!=0 else num, minNagetive*num if minNagetive!=0 else 0
            elif num < 0:
                maxPositive, minNagetive = minNagetive*num if minNagetive!=0 else 0, maxPositive*num if maxPositive!=0 else num
            else:
                maxPositive, minNagetive = 0, 0
            maxValue = max(maxValue, maxPositive)
        return maxValue

print(Solution().maxProduct([0, 2, 2, -1]))